package com.youku
{
   import flash.display.Sprite;
   import flash.display.MovieClip;
   import flash.text.TextField;
   import flash.display.DisplayObject;
   import flash.net.URLLoader;
   import flash.utils.Timer;
   import flash.display.Loader;
   import flash.events.Event;
   import flash.display.StageScaleMode;
   import flash.display.StageAlign;
   import flash.events.MouseEvent;
   import flash.text.TextFormat;
   import flash.text.TextFormatAlign;
   import flash.geom.Rectangle;
   import flash.events.SecurityErrorEvent;
   import flash.events.IOErrorEvent;
   import flash.events.TimerEvent;
   import flash.net.URLRequest;
   import flash.utils.getTimer;
   import com.adobe.json.JSON;
   import flash.net.sendToURL;
   import com.youku.utils.StringUtil;
   import flash.display.LoaderInfo;
   import com.youku.data.LoadTimeData;
   import flash.system.LoaderContext;
   import flash.system.SecurityDomain;
   import flash.net.URLRequestMethod;
   import flash.system.Security;
   
   public class PlayerLoader extends Sprite
   {
      
      public function PlayerLoader() {
         super();
         Security.allowDomain("*");
         if(stage)
         {
            this.init();
         }
         else
         {
            this.addEventListener(Event.ADDED_TO_STAGE,this.onAddToStage);
         }
      }
      
      protected var _errorIcon:MovieClip;
      
      protected var _errorText:TextField;
      
      protected var _errorCode:TextField;
      
      protected var _background:Sprite;
      
      protected var _blankBG:Sprite;
      
      protected var _loading:Sprite;
      
      protected var _errorLayer:Sprite;
      
      protected var _pd:Object = null;
      
      protected var _loadingMovieClip:DisplayObject = null;
      
      protected var _loadingPictureURL:String = "";
      
      protected var _player;
      
      protected var _width:Number;
      
      protected var _height:Number;
      
      protected var _ratio:Number;
      
      protected var _partnerid:String = "";
      
      protected var _videoIDS:String = "";
      
      protected var _category:String = "";
      
      protected var _app_signature:String = "";
      
      protected var _app_timestamp:String = "";
      
      protected var _isTouch:Boolean = false;
      
      protected var _paid:String = "";
      
      protected var _vext:String = "";
      
      protected var _urlLoader:URLLoader;
      
      protected var _urlLoadTimer:Timer;
      
      protected var _urlLoadRetryCount:Number = 0;
      
      protected var _playerLoader:Loader;
      
      protected var _playerLoadTimer:Timer;
      
      protected var _playerLoadRetryCount:Number = 0;
      
      protected var _loadingPictureLoader:Loader;
      
      protected var _loadingPictureTimer:Timer;
      
      protected var _loadingPictureRetryCount:Number = 0;
      
      protected var _delayload:Boolean = false;
      
      protected var _imgLogoMC:DisplayObject = null;
      
      protected var _imgLogoURL:String = "";
      
      protected var _fakeControlbar:MovieClip = null;
      
      protected var _imgLogoLoader:Loader;
      
      protected var _imgLogoTimer:Timer;
      
      protected var _imgLogoRetryCount:Number = 0;
      
      protected var _parametersData:Object;
      
      protected var _isLoadingPlayer:Boolean = false;
      
      protected var MINI_WIDTH:Number = 440;
      
      protected var MINI_HEIGHT:Number = 358;
      
      protected var MAX_WIDTH:Number = 900;
      
      protected var MAX_HEIGHT:Number = 500;
      
      protected var _loadingWidth:Number = 0;
      
      protected var _loadingHeight:Number = 0;
      
      protected var _playerName:String = "";
      
      protected var _ltPartner:Number = 0;
      
      protected var _ltPlayPolicy:Number = 0;
      
      protected var _ltPlayer:Number = 0;
      
      protected var _stPartner:Number = 0;
      
      protected var _stPlayer:Number = 0;
      
      protected var _stPlayPolicy:Number = 0;
      
      protected var _stPlayer_s:Number = 0;
      
      protected const LOAD_STAGE_PARTNER:String = "stage_partner";
      
      protected const LOAD_STAGE_PLAYPOLICY:String = "stage_playpolicy";
      
      protected const LOAD_STAGE_PLAYER:String = "stage_player";
      
      protected const SEND_LOG_RATIO_NUMBER:int = 100;
      
      protected var _uepflag:Boolean;
      
      protected var _pvid:String;
      
      protected var _styleid:int = 0;
      
      protected var _embsig:String = "";
      
      private function onAddToStage(param1:Event) : void {
         removeEventListener(Event.ADDED_TO_STAGE,this.onAddToStage);
         this.init();
      }
      
      private function onStageSizeChange(param1:Event) : void {
         this.setSize(stage.stageWidth,stage.stageHeight);
      }
      
      protected function init() : void {
         stage.scaleMode = StageScaleMode.NO_SCALE;
         stage.align = StageAlign.TOP_LEFT;
         this._width = stage.stageWidth;
         this._height = stage.stageHeight;
         this.parseFlashVar();
         this.initUI();
         this.initOther();
         stage.addEventListener(Event.RESIZE,this.onStageSizeChange);
         this._pd = null;
         if((this._partnerid) || (this._delayload))
         {
            this.removeLoading();
            this._blankBG.visible = true;
            if(this._delayload)
            {
               this._fakeControlbar.visible = true;
               stage.addEventListener(MouseEvent.CLICK,this.onStageClick);
               this.loadImgLogo();
            }
            if(this._partnerid)
            {
               this.loadPartnerParameters();
            }
         }
         else if(this._loadingPictureURL)
         {
            this.removeLoading();
            this._blankBG.visible = true;
            this.loadLoadingPicture();
         }
         else
         {
            this.loadPlayer();
         }
         
      }
      
      private function onStageClick(param1:MouseEvent) : void {
         if(!this._delayload)
         {
            return;
         }
         if(this._imgLogoMC)
         {
            if(contains(this._imgLogoMC))
            {
               removeChild(this._imgLogoMC);
            }
         }
         this.addLoading();
         this.loadPlayer();
      }
      
      private function removeLoading() : void {
         if(this.contains(this._loading))
         {
            this.removeChild(this._loading);
         }
         this._background.visible = false;
      }
      
      private function addLoading() : void {
         this.addChild(this._loading);
         this._background.visible = true;
      }
      
      protected function initUI() : void {
         this._background = new Sprite();
         this._background.graphics.beginFill(15595516);
         this._background.graphics.drawRect(0,0,610,498);
         this._background.graphics.endFill();
         this._blankBG = new Sprite();
         this._blankBG.graphics.beginFill(0);
         this._blankBG.graphics.drawRect(0,0,100,100);
         this._blankBG.graphics.endFill();
         this._loading = new Sprite();
         var _loc1_:MovieClip = new Loading_pic();
         _loc1_.width = 158;
         _loc1_.height = 46;
         var _loc2_:MovieClip = new Loading_Ring();
         _loc2_.width = 36;
         _loc2_.height = 36;
         this._loading.addChild(_loc1_);
         this._loading.addChild(_loc2_);
         _loc1_.x = 0;
         _loc1_.y = 54;
         _loc2_.x = 61;
         _loc2_.y = 0;
         this._loadingWidth = this._loading.width;
         this._loadingHeight = this._loading.height;
         this._errorLayer = new Sprite();
         this._errorText = new TextField();
         var _loc3_:TextFormat = new TextFormat("Microsoft YaHei",18,16777215);
         _loc3_.align = TextFormatAlign.CENTER;
         this._errorText.defaultTextFormat = _loc3_;
         this._errorText.text = "无法加载播放器，请删除浏览器缓存后重试";
         this._errorLayer.addChild(this._errorText);
         this._errorCode = new TextField();
         _loc3_ = new TextFormat("Microsoft YaHei",12,10066329);
         _loc3_.align = TextFormatAlign.CENTER;
         this._errorCode.defaultTextFormat = _loc3_;
         this._errorCode.text = "代码 : 5000";
         this._errorLayer.addChild(this._errorCode);
         this._errorIcon = new P_icon_info();
         this._errorLayer.addChild(this._errorIcon);
         this._fakeControlbar = new Controll_bar_mini();
         this._fakeControlbar.scale9Grid = new Rectangle(60,1,180,11);
         addChild(this._blankBG);
         addChild(this._background);
         addChild(this._loading);
         addChild(this._errorLayer);
         addChild(this._fakeControlbar);
         this._blankBG.visible = false;
         this._errorLayer.visible = false;
         this._fakeControlbar.visible = false;
         this.setSize(this._width,this._height);
      }
      
      private function initOther() : void {
         this._urlLoader = new URLLoader();
         this._urlLoader.addEventListener(Event.COMPLETE,this.onLoadParameterComplete);
         this._urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onLoadParameterError);
         this._urlLoader.addEventListener(IOErrorEvent.IO_ERROR,this.onLoadParameterError);
         this._urlLoadTimer = new Timer(5 * 1000);
         this._urlLoadTimer.addEventListener(TimerEvent.TIMER,this.onLoadParameterTimeout);
         this._playerLoadTimer = new Timer(30 * 1000);
         this._playerLoadTimer.addEventListener(TimerEvent.TIMER,this.onPlayerLoadTimeout);
         this._loadingPictureTimer = new Timer(5 * 1000);
         this._loadingPictureTimer.addEventListener(TimerEvent.TIMER,this.onLoadingPictureLoadTimeout);
      }
      
      private function preparePlayerName() : void {
         var _loc1_:PlayPolicyProxy = null;
         if(this._isTouch)
         {
            this._playerName = "/player_touch.swf";
            this.reallyLoadPlayer();
         }
         else
         {
            _loc1_ = new PlayPolicyProxy();
            _loc1_.addEventListener(PlayerLoader.PLAY_POLICY_READY,this.onPlayPolicyReady);
            _loc1_.loadPolicy(this._videoIDS,this._category,this._paid);
            this._stPlayPolicy = new Date().getTime();
         }
      }
      
      private function onPlayPolicyReady(param1:PlayPolicyEvent) : void {
         this._ltPlayPolicy = param1.data.lt;
         var _loc2_:Boolean = param1.data.error;
         if(_loc2_)
         {
            this.sendLoadTimeLog(this.LOAD_STAGE_PLAYPOLICY,true,0);
         }
         var _loc3_:String = null;
         if(_loc2_)
         {
            if(param1.data.hasOwnProperty("errorCode"))
            {
               _loc3_ = param1.data.errorCode;
            }
         }
         var _loc4_:Boolean = param1.data.allow;
         var _loc5_:* = "player.swf";
         if(param1.data.swf != null)
         {
            _loc5_ = param1.data.swf;
         }
         this._playerName = "/" + _loc5_;
         this._parametersData.policy = true;
         this._parametersData.allowp2p = _loc4_;
         this.reportLoadTime(this.LOAD_STAGE_PLAYPOLICY,_loc2_,_loc3_);
         this.reallyLoadPlayer();
      }
      
      private function reallyLoadPlayer() : void {
         var _loc1_:String = this.loaderInfo.url;
         _loc1_ = _loc1_.substr(0,_loc1_.search(new RegExp("\\/[^\\/]*\\.swf")));
         _loc1_ = _loc1_ + this._playerName;
         if(this._playerLoadRetryCount > 0)
         {
            _loc1_ = _loc1_ + ("?retry=" + this._playerLoadRetryCount);
         }
         this._playerLoader = new Loader();
         this._playerLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onPlayerLoadComplete);
         this._playerLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onPlayerLoadSecurityError);
         this._playerLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onPlayerLoadIOError);
         this._playerLoader.load(new URLRequest(_loc1_));
         this._isLoadingPlayer = true;
         this._stPlayer = getTimer();
         this._stPlayer_s = new Date().getTime();
         this._playerLoadTimer.reset();
         this._playerLoadTimer.start();
      }
      
      private function loadPlayer() : void {
         stage.removeEventListener(MouseEvent.CLICK,this.onStageClick);
         if(this._playerName == "")
         {
            this.preparePlayerName();
         }
         else
         {
            this.reallyLoadPlayer();
         }
      }
      
      private function retryLoadPlayer(param1:String) : void {
         var _loc2_:Object = null;
         var _loc3_:String = null;
         this._playerLoadRetryCount++;
         if(this._playerLoadRetryCount <= 1)
         {
            this.loadPlayer();
         }
         else
         {
            this._blankBG.visible = true;
            this._errorLayer.visible = true;
            this._background.visible = false;
            this._loading.visible = false;
            if(this._imgLogoMC)
            {
               this._imgLogoMC.visible = false;
            }
            if(this._loadingMovieClip)
            {
               this._loadingMovieClip.visible = false;
            }
            _loc2_ = {};
            _loc2_.code = "5000";
            _loc2_.player = this._playerName;
            _loc3_ = "http://passport-log.youku.com/logsys/logstorage/append?project=loaderror&log=";
            _loc3_ = _loc3_ + com.adobe.json.JSON.encode(_loc2_);
            sendToURL(new URLRequest(_loc3_));
            this.reportLoadTime(this.LOAD_STAGE_PLAYER,true,param1);
         }
      }
      
      private function retryLoadParameter() : void {
         this._urlLoadRetryCount++;
         if(this._urlLoadRetryCount <= 0)
         {
            this.loadPartnerParameters();
         }
         else
         {
            this.loadPlayer();
         }
      }
      
      private function setSize(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = param2;
         this._background.width = param1;
         this._background.height = param2;
         this._blankBG.width = param1;
         this._blankBG.height = param2;
         this._ratio = 1;
         if(param1 < this.MINI_WIDTH || param2 < this.MINI_HEIGHT)
         {
            if(param1 / this.MINI_WIDTH > param2 / this.MINI_HEIGHT)
            {
               this._ratio = param2 / this.MINI_HEIGHT;
            }
            else
            {
               this._ratio = param1 / this.MINI_WIDTH;
            }
         }
         if(param1 > this.MAX_WIDTH || param2 > this.MAX_HEIGHT)
         {
            if(param1 / this.MAX_WIDTH > param2 / this.MAX_HEIGHT)
            {
               this._ratio = param2 / this.MAX_HEIGHT;
            }
            else
            {
               this._ratio = param1 / this.MAX_WIDTH;
            }
         }
         this._loading.scaleX = this._ratio;
         this._loading.scaleY = this._ratio;
         var _loc3_:Number = this._errorText.textWidth + 20;
         var _loc4_:Number = param1 / _loc3_ > 1?1:param1 / _loc3_;
         this._errorText.width = this._errorCode.width = _loc3_;
         this._errorText.height = this._errorCode.height = this._errorText.textHeight + 4;
         this._errorLayer.scaleX = this._errorLayer.scaleY = _loc4_;
         this._fakeControlbar.width = param1;
         if(this._imgLogoMC)
         {
            this._imgLogoMC.width = param1;
            this._imgLogoMC.height = param2 - this._fakeControlbar.height;
         }
         if(this._loadingMovieClip)
         {
            this.adjustWH(this._loadingMovieClip);
         }
         this.updateLayout();
      }
      
      protected function adjustWH(param1:DisplayObject) : void {
         var _loc4_:* = NaN;
         var _loc5_:* = NaN;
         var _loc2_:Number = param1.width;
         var _loc3_:Number = param1.height;
         if(_loc2_ / _loc3_ > this._width / this._height)
         {
            _loc4_ = this._width;
            _loc5_ = this._width * _loc3_ / _loc2_;
         }
         else
         {
            _loc5_ = this._height;
            _loc4_ = this._height * _loc2_ / _loc3_;
         }
         param1.width = _loc4_;
         param1.height = _loc5_;
      }
      
      protected function updateLayout() : void {
         this._background.x = this._background.y = 0;
         this._blankBG.x = this._blankBG.y = 0;
         this._errorIcon.x = int((this._errorText.width - this._errorIcon.width) / 2);
         this._errorIcon.y = 0;
         this._errorText.x = 0;
         this._errorText.y = 100;
         this._errorCode.x = 0;
         this._errorCode.y = 200;
         this._errorLayer.x = int((this._background.width - this._errorLayer.width) / 2);
         this._errorLayer.y = int((this._background.height - this._errorLayer.height) / 2);
         this._loading.x = (this._width - this._loadingWidth * this._loading.scaleX) / 2;
         this._loading.y = (this._height - this._loadingHeight * this._loading.scaleY) / 2;
         if(this._loadingMovieClip)
         {
            this._loadingMovieClip.x = (this._width - this._loadingMovieClip.width) / 2;
            this._loadingMovieClip.y = (this._height - this._loadingMovieClip.height) / 2;
         }
         if(this._imgLogoMC)
         {
            this._imgLogoMC.x = 0;
            this._imgLogoMC.y = 0;
         }
         this._fakeControlbar.x = 0;
         this._fakeControlbar.y = this._height - this._fakeControlbar.height;
      }
      
      protected function parseFlashVar() : void {
         var _loc1_:String = null;
         this._parametersData = stage.loaderInfo.parameters;
         for(_loc1_ in this.loaderInfo.parameters)
         {
            this._parametersData[_loc1_] = this.loaderInfo.parameters[_loc1_];
         }
         if(this._parametersData.hasOwnProperty("paid"))
         {
            this._paid = this._parametersData.paid;
         }
         if(this._parametersData.hasOwnProperty("partnerid"))
         {
            this._partnerid = this._parametersData.partnerid;
         }
         if(this._parametersData.hasOwnProperty("VideoIDS"))
         {
            this._videoIDS = this._parametersData.VideoIDS;
         }
         if(this._parametersData.hasOwnProperty("category"))
         {
            this._category = this._parametersData.category;
         }
         if(this._parametersData.hasOwnProperty("app_signature"))
         {
            this._app_signature = this._parametersData.app_signature;
         }
         if(this._parametersData.hasOwnProperty("app_timestamp"))
         {
            this._app_timestamp = this._parametersData.app_timestamp;
         }
         if(this._parametersData.hasOwnProperty("touch"))
         {
            if(String(this._parametersData["touch"]).toLowerCase() == "true")
            {
               this._isTouch = true;
            }
         }
         if(this._parametersData.hasOwnProperty("delayload"))
         {
            if(String(this._parametersData["delayload"]).toLowerCase() == "true")
            {
               this._delayload = true;
            }
         }
         if(this._parametersData.hasOwnProperty("imglogo"))
         {
            if(StringUtil.isDomianLegal(this._parametersData.imglogo))
            {
               this._imgLogoURL = this._parametersData.imglogo;
            }
         }
         if(this._parametersData.hasOwnProperty("vext"))
         {
            this._vext = this._parametersData.vext;
         }
         if(this._parametersData.hasOwnProperty("loadinglogo"))
         {
            if(StringUtil.isDomianLegal(this._parametersData.loadinglogo))
            {
               this._loadingPictureURL = this._parametersData.loadinglogo;
            }
         }
         if(this._parametersData.hasOwnProperty("uepflag"))
         {
            if(this._parametersData["uepflag"] == "1")
            {
               this._uepflag = true;
            }
            else
            {
               this._uepflag = false;
            }
         }
         if(this._parametersData.hasOwnProperty("pvid"))
         {
            if(this._parametersData["pvid"] != "")
            {
               this._pvid = this._parametersData["pvid"];
            }
         }
         if(this._parametersData.hasOwnProperty("styleid"))
         {
            this._styleid = this._parametersData["styleid"];
         }
         if(this._parametersData.hasOwnProperty("embsig"))
         {
            this._embsig = this._parametersData["embsig"];
         }
      }
      
      protected function loadPartnerParameters() : void {
         var refer:String = "";
         try
         {
            refer = YoukuExternalInterface.call("window.location.href.toString");
         }
         catch(e:Error)
         {
         }
         refer = encodeURIComponent(refer);
         var url:String = "https://openapi.youku.com/v2/players/custom.json?";
         url = url + ("client_id=" + this._partnerid);
         url = url + ("&video_id=" + this._videoIDS);
         url = url + ("&refer=" + refer);
         url = url + ("&vext=" + encodeURIComponent(this._vext));
         url = url + ("&embsig=" + this._embsig);
         url = url + ("&styleid=" + String(this._styleid));
         this._urlLoader.load(new URLRequest(url));
         this._urlLoadTimer.reset();
         this._urlLoadTimer.start();
         this._stPartner = getTimer();
      }
      
      private function onLoadParameterComplete(param1:Event) : void {
         this._urlLoadTimer.stop();
         this._ltPartner = getTimer() - this._stPartner;
         this.sendLoadTimeLog(this.LOAD_STAGE_PARTNER,false,this._urlLoadRetryCount);
         var _loc2_:String = URLLoader(param1.currentTarget).data;
         this.parsePartnerData(_loc2_);
      }
      
      private function onLoadParameterError(param1:Event) : void {
         var e:Event = param1;
         this._urlLoadTimer.stop();
         this._ltPartner = getTimer() - this._stPartner;
         this.sendLoadTimeLog(this.LOAD_STAGE_PARTNER,true,this._urlLoadRetryCount);
         try
         {
            this._urlLoader.close();
         }
         catch(e:Error)
         {
         }
         this.retryLoadParameter();
      }
      
      private function onLoadParameterTimeout(param1:TimerEvent) : void {
         this.onLoadParameterError(param1);
      }
      
      private function onPlayerLoadComplete(param1:Event) : void {
         var showplayer:Function = null;
         var e:Event = param1;
         showplayer = function():void
         {
            _player.visible = true;
            if(contains(_loading))
            {
               removeChild(_loading);
            }
            if(_loadingMovieClip)
            {
               if(contains(_loadingMovieClip))
               {
                  try
                  {
                     removeChild(_loadingMovieClip);
                  }
                  catch(e:Error)
                  {
                  }
               }
            }
            _loadingMovieClip = null;
            if(contains(_fakeControlbar))
            {
               removeChild(_fakeControlbar);
            }
            try
            {
               YoukuExternalInterface.call("notifyYKU");
            }
            catch(e:Error)
            {
            }
         };
         this._playerLoadTimer.stop();
         this._ltPlayer = getTimer() - this._stPlayer;
         this._parametersData.ltpartner = this._ltPartner;
         this._parametersData.ltplaypolicy = this._ltPlayPolicy;
         this._parametersData.ltplayer = this._ltPlayer;
         this._player = (e.target as LoaderInfo).loader.content;
         addChild(this._player);
         this._player.visible = false;
         this._player.x = 0;
         this._player.y = 0;
         this._player.initPlayer(this._pd,this._parametersData,this._loadingMovieClip);
         this.reportLoadTime(this.LOAD_STAGE_PLAYER,false,null);
         showplayer.call();
      }
      
      private function onPlayerLoadSecurityError(param1:Event) : void {
         this.onPlayerLoadError(LoadTimeData.ERROR_CODE_SECURITY);
      }
      
      private function onPlayerLoadIOError(param1:IOErrorEvent) : void {
         this.onPlayerLoadError(LoadTimeData.ERROR_CODE_IO);
      }
      
      private function onPlayerLoadTimeout(param1:TimerEvent) : void {
         this.onPlayerLoadError(LoadTimeData.ERROR_CODE_TIMEOUT);
      }
      
      private function onPlayerLoadError(param1:String) : void {
         var eCode:String = param1;
         this._playerLoadTimer.stop();
         this._ltPlayer = getTimer() - this._stPlayer;
         try
         {
            this._playerLoader.close();
         }
         catch(e:Error)
         {
         }
         this.sendLoadTimeLog(this.LOAD_STAGE_PLAYER,true,this._playerLoadRetryCount);
         this.retryLoadPlayer(eCode);
      }
      
      private function parsePartnerData(param1:String) : void {
         var str:String = param1;
         var data:Object = null;
         try
         {
            data = com.adobe.json.JSON.decode(str);
         }
         catch(e:Error)
         {
            data = null;
         }
         this._pd = data;
         if((data && data.noband) && (data.noband.status == 1) && !(data.noband.loadingurl == ""))
         {
            if(StringUtil.isDomianLegal(data.noband.loadingurl))
            {
               this._loadingPictureURL = data.noband.loadingurl;
            }
            this.loadLoadingPicture();
         }
         else
         {
            if((data) && (data.noband) && data.noband.status == 0)
            {
               this.addLoading();
               this._blankBG.visible = false;
            }
            this.loadPlayer();
         }
      }
      
      private function loadLoadingPicture() : void {
         if(this._loadingPictureURL == null || this._loadingPictureURL == "")
         {
            this.onLoadingPictureReady();
            return;
         }
         this._loadingPictureLoader = new Loader();
         this._loadingPictureLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onLoadingPictureComplete);
         this._loadingPictureLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onLoadingPictureError);
         this._loadingPictureLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onLoadingPictureError);
         var _loc1_:LoaderContext = new LoaderContext(true);
         _loc1_.checkPolicyFile = true;
         _loc1_.securityDomain = SecurityDomain.currentDomain;
         this._loadingPictureLoader.load(new URLRequest(this._loadingPictureURL),_loc1_);
         this._loadingPictureTimer.reset();
         this._loadingPictureTimer.start();
      }
      
      private function onLoadingPictureComplete(param1:Event) : void {
         var e:Event = param1;
         this._loadingPictureTimer.stop();
         var content:DisplayObject = null;
         try
         {
            content = (e.target as LoaderInfo).loader.content;
            if(!(content == null) && content.width > 0 && content.height > 0)
            {
               this._loadingMovieClip = content;
            }
         }
         catch(e:Error)
         {
            _loadingMovieClip = null;
         }
         this.onLoadingPictureReady();
      }
      
      private function onLoadingPictureError(param1:Event) : void {
         this._loadingPictureTimer.stop();
         this.retryLoadLoadingPicture();
      }
      
      private function onLoadingPictureLoadTimeout(param1:TimerEvent) : void {
         var e:TimerEvent = param1;
         try
         {
            this._loadingPictureLoader.close();
         }
         catch(e:Error)
         {
         }
         this._loadingPictureTimer.stop();
         this.retryLoadLoadingPicture();
      }
      
      private function retryLoadLoadingPicture() : void {
         this._loadingPictureRetryCount++;
         if(this._loadingPictureRetryCount <= 0)
         {
            this.loadLoadingPicture();
         }
         else
         {
            this.onLoadingPictureReady();
         }
      }
      
      private function onLoadingPictureReady() : void {
         if(this._pd)
         {
            this._pd.loadingMovieClip = this._loadingMovieClip;
         }
         if(this._loadingMovieClip)
         {
            this.addChild(this._loadingMovieClip);
            this._loadingMovieClip.visible = true;
            this.setSize(this._width,this._height);
         }
         this.loadPlayer();
      }
      
      private function loadImgLogo() : void {
         if(this._imgLogoURL == null || this._imgLogoURL == "")
         {
            this.onImgLogoReady();
            return;
         }
         this._imgLogoLoader = new Loader();
         this._imgLogoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onImgLogoComplete);
         this._imgLogoLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onImgLogoError);
         this._imgLogoLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onImgLogoError);
         var _loc1_:LoaderContext = new LoaderContext(true);
         _loc1_.checkPolicyFile = true;
         this._imgLogoLoader.load(new URLRequest(this._imgLogoURL),_loc1_);
         this._imgLogoTimer = new Timer(5 * 1000);
         this._imgLogoTimer.addEventListener(TimerEvent.TIMER,this.onImgLogoTimout);
         this._imgLogoTimer.reset();
         this._imgLogoTimer.start();
      }
      
      private function onImgLogoTimout(param1:TimerEvent) : void {
         var e:TimerEvent = param1;
         try
         {
            this._imgLogoLoader.close();
         }
         catch(e:Error)
         {
         }
         this._imgLogoTimer.stop();
         this.onImgLogoReady();
      }
      
      private function onImgLogoError(param1:Event) : void {
         this._imgLogoTimer.stop();
         this.onImgLogoReady();
      }
      
      private function onImgLogoComplete(param1:Event) : void {
         var e:Event = param1;
         this._imgLogoTimer.stop();
         var content:DisplayObject = null;
         try
         {
            content = (e.target as LoaderInfo).loader.content;
            if(!(content == null) && content.width > 0 && content.height > 0)
            {
               this._imgLogoMC = content;
            }
         }
         catch(e:Error)
         {
            _imgLogoMC = null;
         }
         this.onImgLogoReady();
      }
      
      private function onImgLogoReady() : void {
         if((this._imgLogoMC) && !this._isLoadingPlayer)
         {
            this.addChild(this._imgLogoMC);
            if(getChildIndex(this._imgLogoMC) > getChildIndex(this._fakeControlbar))
            {
               swapChildren(this._imgLogoMC,this._fakeControlbar);
            }
            this.setSize(this._width,this._height);
         }
      }
      
      protected function sendLoadTimeLog(param1:String, param2:Boolean, param3:int) : void {
         var _loc4_:int = int(Math.random() * 100);
         if(_loc4_ % this.SEND_LOG_RATIO_NUMBER != 50)
         {
            return;
         }
         var _loc5_:* = "http://passport-log.youku.com/logsys/logstorage/append?project=playerloadtime&log=";
         var _loc6_:Object = new Object();
         _loc6_.type = param2?"error":"report";
         _loc6_.stage = param1;
         _loc6_.info = param3;
         _loc6_.report = {};
         if(param1 == this.LOAD_STAGE_PARTNER)
         {
            _loc6_.report.ltpartner = this._ltPartner;
         }
         else
         {
            _loc6_.report.ltplayer = this._ltPlayer;
            _loc6_.report.ltplaypolicy = this._ltPlayPolicy;
         }
         _loc5_ = _loc5_ + com.adobe.json.JSON.encode(_loc6_);
         var _loc7_:URLRequest = new URLRequest(_loc5_);
         _loc7_.method = URLRequestMethod.GET;
         sendToURL(_loc7_);
      }
      
      protected function reportLoadTime(param1:String, param2:Boolean, param3:String) : void {
         var t:String = null;
         var s:String = null;
         var st:String = null;
         var et:String = null;
         var stage:String = param1;
         var iserror:Boolean = param2;
         var eCode:String = param3;
         if(!iserror)
         {
            if(this._pvid == null || this._uepflag == false)
            {
               return;
            }
         }
         var uepUrl:String = "http://v.l.youku.com/uep?";
         var m:String = "flashplayer";
         if(this._playerName == "/player_ss.swf")
         {
            m = "ssplayer";
         }
         else if(this._playerName == "/player_yk.swf" || this._playerName == "/player_yknp.swf")
         {
            m = "p2pplayer";
         }
         else if(this._playerName == "/player_pw.swf")
         {
            m = "ppwebplayer";
         }
         
         
         uepUrl = uepUrl + ("m=" + m);
         var refer:String = "";
         try
         {
            refer = YoukuExternalInterface.call("window.location.href.toString");
         }
         catch(e:Error)
         {
         }
         refer = encodeURIComponent(refer);
         uepUrl = uepUrl + ("&u=" + refer);
         if(stage == this.LOAD_STAGE_PLAYER)
         {
            t = "playerload";
            s = String(this._ltPlayer);
            st = String(this._stPlayer_s);
            et = String(new Date().getTime());
         }
         else if(stage == this.LOAD_STAGE_PLAYPOLICY)
         {
            t = "playpolicy";
            s = String(this._ltPlayPolicy);
            st = String(this._stPlayPolicy);
            et = String(new Date().getTime());
         }
         
         if(iserror)
         {
            s = "-1";
         }
         uepUrl = uepUrl + ("&t=" + t);
         uepUrl = uepUrl + ("&s=" + s);
         uepUrl = uepUrl + ("&st=" + st);
         uepUrl = uepUrl + ("&et=" + et);
         if(eCode != null)
         {
            uepUrl = uepUrl + ("&e=" + eCode);
         }
         uepUrl = uepUrl + ("&pid=" + this._pvid);
         sendToURL(new URLRequest(uepUrl));
      }
      
      public function get player() : * {
         return this._player;
      }
   }
}
import flash.events.EventDispatcher;
import flash.net.URLLoader;
import flash.utils.Timer;
import flash.events.IOErrorEvent;
import com.youku.data.LoadTimeData;
import flash.events.SecurityErrorEvent;
import flash.events.Event;
import flash.utils.getTimer;
import com.adobe.json.JSON;
import com.youku.utils.FlashVersionCheck;
import flash.events.TimerEvent;
import flash.net.URLRequest;

class PlayPolicyProxy extends EventDispatcher
{
   
   function PlayPolicyProxy() {
      super();
      this._timer = new Timer(this._loadTimeout,1);
      this._timer.addEventListener(TimerEvent.TIMER_COMPLETE,this.onTimeout);
      this._loader = new URLLoader();
      this._loader.addEventListener(Event.COMPLETE,this.onLoadComplete);
      this._loader.addEventListener(IOErrorEvent.IO_ERROR,this.onLoadIOError);
      this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onLoadSecurityError);
   }
   
   private var _loader:URLLoader;
   
   private var _timer:Timer;
   
   private var _loadTimeout:Number = 5000.0;
   
   private var _lt:Number = 0;
   
   private var _st:Number = 0;
   
   private const PLAY_POLICY_URL:String = "http://yk.pp.navi.youku.com/playpolicy/get.json";
   
   private function onLoadIOError(param1:IOErrorEvent) : void {
      this.onLoadError(LoadTimeData.ERROR_CODE_IO);
   }
   
   private function onLoadSecurityError(param1:SecurityErrorEvent) : void {
      this.onLoadError(LoadTimeData.ERROR_CODE_SECURITY);
   }
   
   private function onLoadComplete(param1:Event) : void {
      var e:Event = param1;
      this._timer.stop();
      this._lt = getTimer() - this._st;
      var allow:Boolean = false;
      var swf:String = "player.swf";
      var str:String = URLLoader(e.currentTarget).data;
      var obj:Object = {};
      try
      {
         obj = com.adobe.json.JSON.decode(str);
      }
      catch(e:Error)
      {
      }
      if(obj.hasOwnProperty("dataset"))
      {
         if(obj.dataset.p2p[0].player)
         {
            swf = obj.dataset.p2p[0].player + ".swf";
            if(swf == "player_ss.swf" || swf == "player_yk.swf" || swf == "player_pw.swf")
            {
               allow = true;
            }
         }
      }
      else
      {
         allow = false;
      }
      if(!FlashVersionCheck.checkVersionForNewVersion())
      {
         if(swf != "player_yk.swf")
         {
            swf = "player_yk.swf";
            allow = false;
         }
      }
      dispatchEvent(new PlayPolicyEvent(PlayPolicyProxy.PLAY_POLICY_READY,
         {
            "allow":allow,
            "swf":swf,
            "error":false,
            "lt":this._lt
         }));
   }
   
   private function onLoadError(param1:String) : void {
      var error:String = param1;
      this._timer.stop();
      this._lt = getTimer() - this._st;
      try
      {
         this._loader.close();
      }
      catch(e:Error)
      {
      }
      dispatchEvent(new PlayPolicyEvent(PlayPolicyProxy.PLAY_POLICY_READY,
         {
            "allow":false,
            "error":true,
            "lt":this._lt,
            "errorCode":error
         }));
   }
   
   private function onTimeout(param1:TimerEvent) : void {
      this.onLoadError(LoadTimeData.ERROR_CODE_TIMEOUT);
   }
   
   public function loadPolicy(param1:String, param2:String, param3:String) : void {
      var _loc4_:* = this.PLAY_POLICY_URL + "?";
      _loc4_ = _loc4_ + ("vid_encode=" + param1);
      _loc4_ = _loc4_ + ("&category=" + param2);
      if(param3 == "1")
      {
         _loc4_ = _loc4_ + ("&paid=" + param3);
      }
      this._st = getTimer();
      this._timer.reset();
      this._timer.start();
      var _loc5_:URLRequest = new URLRequest(_loc4_);
      this._loader.load(_loc5_);
   }
}
import flash.events.Event;

class PlayPolicyEvent extends Event
{
   
   function PlayPolicyEvent(param1:String, param2:Object = null) {
      super(param1,false,false);
      this._data = param2;
   }
   
   public static const PLAY_POLICY_READY:String = "PLAY_POLICY_READY";
   
   private var _data:Object = null;
   
   public function get data() : Object {
      return this._data;
   }
   
   public function set data(param1:Object) : void {
      this._data = param1;
   }
}
